// 这是一个订单的存储库
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useOrderStore = defineStore('order', () => {
  const orders = ref([])

  const addOrder = (order) => {
    orders.value.unshift(order)
  }

  const getOrders = () => {
    return orders.value
  }

  const getOrderById = (orderId) => {
    return orders.value.find(order => order.orderId === orderId)
  }

  const updateOrderStatus = (orderId, status) => {
    const order = orders.value.find(order => order.orderId === orderId)
    if (order) {
      order.status = status
    }
  }

  return {
    orders,
    addOrder,
    getOrders,
    getOrderById,
    updateOrderStatus
  }
}) 